import React, { Component, Fragment } from 'react'
import { Redirect } from 'react-router-dom'
import { message } from 'antd'

export default function IsLogin(MyComponent) {
    return  class extends Component {
        state = {
            Template:null
        }
        componentDidMount(){
            let token = localStorage.getItem("token")
            if(token){
                this.setState({
                    Template:<MyComponent {...this.props} />
                })
            }else{
                message.error("请先登录")
                this.setState({
                    Template:<Redirect to="/login" />
                })
            }
        }
        render() {
            let {Template} = this.state
            return (
                <Fragment>
                    {
                        Template
                    }
                </Fragment>
            )
        }
    }
    
}
